<template>
  <div>
    <swiper :options="swiperOption" key="iconSwiper">
      <!-- slides -->
      <swiper-slide v-for="(page,index) of pages" :key="index" class="iconBg">
        <div class="icon" v-for="item of page" :key="item.pid">
          <div>
            <img :src="item.imgUrl" class="listImg" />
          </div>
          <p>{{item.name}}</p>
        </div>
      </swiper-slide>
      <!-- Optional controls -->
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
import _ from "lodash";

export default {
  props: {
    icons: {
      type: Array,
      default: null
    }
  },
  name: "iconsView",
  data() {
    return {
      swiperOption: {
        pagination: ".swiper-pagination",
        loop: true
      }
    };
  },
  computed: {
    pages() {
      let pages = _.chunk(this.icons, 8);
      return pages;
    }
  },
  created() {}
};
</script>

<style lang="stylus" scoped>4;

@import '~@styl';

swiper >>> .swiper-pagination-bullet-active {
  background: $navBgColor;
}

.iconBg {
  margin-top: 0.1rem;
  overflow: hidden;
  height: 0;
  padding-bottom: 50%;
  display: flex;
  flex-wrap: wrap;

  .icon {
    overflow: hidden;
    width: 25%;
    height: 0;
    padding-bottom: 25%;
    display: flex;
    flex-direction: column;
    align-items: center;

    .listImg {
      width: 0.55rem;
      height: 0.55rem;
    }

    p {
      margin-top: 0.05rem;
      font-size: 0.13rem;
      text-align: center;
      display: block;
    }
  }
}
</style>